package app;

import javax.swing.JOptionPane;
import javax.swing.SwingUtilities;

import app.gui.MainFrame;

/**
 * 
 * 
 * @author Lukas Vavra
 *
 *
 *
 */
public class Main {
	public static final String FRAME_TITLE = "Greenhouse Manager v.0.8";

	private static String token;
	private static String userName;
	
	public static AppConfig appcnf;

	public static synchronized void setToken(String token, String userName) {
		Main.token = token;
		Main.userName = userName;
	}

	public static synchronized String getToken() {
		return Main.token;
	}
	
	public static synchronized String getUserName() {
		return Main.userName;
	}


	public static synchronized boolean isLogged() {		
		return (Main.token == null) ? false : true;
	}

	/**
	 * Show error message dialog
	 * 
	 * @param title Dialog title
	 * @param msg Error message
	 */
	public static synchronized void showError(String title, String msg) {
		JOptionPane.showMessageDialog(null, msg, title, JOptionPane.ERROR_MESSAGE);
	}

	/**
	 * Show info dialog
	 *  
	 * @param msg Info message
	 */
	public static synchronized void showInfo(String msg) {
		JOptionPane.showMessageDialog(null, msg);
	}



	/**
	 * Input method
	 * 
	 * @param args Input arguments from command line
	 */
	public static void main(String[] args) {
		// Get application config
		Main.appcnf = new AppConfig();
		
		if(appcnf.getToken() != null)
			Main.setToken(appcnf.getToken(), appcnf.getName());
		
		SwingUtilities.invokeLater(new Runnable() {

			@Override
			public void run() {
				MainFrame.getInstance();
			}
		});
	}
}
